local mathutils = {}

function mathutils.signum(x)
  local ret = 0
  if x < 0 then
    ret = -1
  elseif x > 0 then
    ret = 1
  end
  return ret
end

function mathutils.clamp(x, minimum, maximum, wrap)
  if wrap then
    x = (x - minimum) % (maximum - minimum)
    if x < 0 then
      x = x + maximum - minimum
    end
    x = x + minimum
  else
    if x < minimum then
      x = minimum
    elseif x > maximum then
      x = maximum
    end
  end
  return x
end

return mathutils
